using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebUI.BL.News;
namespace WebUI
{
    public partial class NewsAdler : WebUI.Lang.AdlerBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            hdfIdCategory.Value = String.IsNullOrEmpty(Request.QueryString["idCategory"]) ? "0" : Request.QueryString["idCategory"];
            hdfIdNews.Value = String.IsNullOrEmpty(Request.QueryString["idItem"]) ? "0" : Request.QueryString["idItem"];
            hdfLangId.Value = Request.Cookies["langId"].Value;
            if(!IsPostBack)
            {
                if(hdfIdNews.Value=="0")
                {
                    BindData();
                    GetTitleCategory();
                }
                else
                {
                    panel1.Visible = false;
                    GetFullDewsc();
                }
                
            }
        }

        private void GetTitleCategory()
        {
            int idCategory = int.Parse(hdfIdCategory.Value);
            var repository = new NewsBL();
            lblTitle.Text = repository.GetTitleCategory(idCategory,int.Parse(hdfLangId.Value));
        }

        private void GetFullDewsc()
        {
            int idNews = int.Parse(hdfIdNews.Value);
            var repository = new NewsBL();
            txtFullDesc.Text = repository.GetNewsByNewsno(idNews).NewsContent;

        }

        private void BindData()
        {
            int idCategory = int.Parse(hdfIdCategory.Value);
            var repository = new NewsBL();
            var source = repository.GetNewsByCategory(idCategory, int.Parse(hdfLangId.Value));
            rptNews.DataSource = source.Select(x => new
                                                        {
                                                            thumbsId=x.Thumb,
                                                            shortDesc=x.ShortDescription,
                                                            dateView =x.CreatedDate,
                                                            nameTitle=x.Title,
                                                            indexShow=x.IndexShow,
                                                            review=x.ViewCount,
                                                            idCategory=x.CategoryNo,
                                                            idItem=x.NewsNo
                                                        }).OrderBy(x=>x.indexShow);
            rptNews.DataBind();
        }
    }
}